<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="com.semanticvoid.lifelogger.karma.search.interfaces.ISearch" %>
<%@ page import="com.semanticvoid.lifelogger.configuration.Constants" %>
<%@ page import="com.semanticvoid.lifelogger.configuration.ConfigManager" %>
<%@ page import="com.semanticvoid.lifelogger.entity.BrowseHistoryEntity" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.semanticvoid.lifelogger.karma.search.factory.SearchFactory" %>
<%@ page import="com.semanticvoid.lifelogger.metrics.browse.SummaryOfTheDay" %>


<%
ISearch searcher = (ISearch) session.getAttribute("searcher");
String query = (String) session.getAttribute("query");
short type = (Short) session.getAttribute("type");
String fromDate = (String) session.getAttribute("fdate");
String toDate = (String) session.getAttribute("tdate");
SummaryOfTheDay summaryOfTheDay = new SummaryOfTheDay(toDate);
Collection<BrowseHistoryEntity> summaryResults = summaryOfTheDay.summarize();
%>
<div id="summaryResults" style="overflow:auto; width:100%;">
    <table cellspacing="2" border="0" style="width:100%;">
        <tr>
            <td style="vertical-align: center; background-color: rgb(204, 204, 204);">
                <font size="2">&nbsp;<b>Interesting picks of the day</b></font><br>
                <font size="1">&nbsp;&nbsp;<%= summaryResults.size() %> result(s)</font>
            </td>
            <td style="vertical-align: center; background-color: rgb(204, 204, 204);" width="10px">
                <a href="#" onclick="toggle_visibility('summaryResultsInner'); toggle_txt('summaryResultsInner'); return false;"><font size="1"> <div id="summaryResultsInnerTxt"> [hide] </div> </font></a>
            </td>
        </tr>
        
        <tr>
            <td colspan="2" style="background-color: #FFFFFF; border: #CCCCCC solid 1px">
                <div id="summaryResultsInner" style="overflow:auto; width:100%; display: block;">
                    <table cellspacing="2" border="0" style="width:100%;">
                        <%
                        if(summaryResults.size() == 0) {
                        %>
                        <tr>
                            <td>
                                &nbsp;
                            </td>    
                        </tr>
                        <tr>
                            <td align="center">
                                <b><font color="#000000">Not an interesting day :(</font></b>
                            </td>    
                        </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>    
                        </tr>
                        <%} else {%>
                        <tr>
                            <td align="left">
                                <img src="./image/legend.png" />
                            </td>
                        </tr>
                        <% } %>
                        
                        <%
                        int i=0;
                        Iterator itr = summaryResults.iterator();
                        
                        while(itr.hasNext()) {
                        //for(int i=0; i<summaryResults.size(); i++) {
                            BrowseHistoryEntity bEntity = (BrowseHistoryEntity) itr.next();
                            i++;
                        %>
                        <tr style="color: #ffffff;">
                            
                            <% switch(bEntity.getType()) {
                                case Constants.ITEM_TYPE_FOR_BROWSE: // Light Blue
                            %> <td style="vertical-align: top; background-color: #94cbdb;"> <%
                            break;
                                case Constants.ITEM_TYPE_FOR_BOOKMARK: // Light red
                            %> <td style="vertical-align: top; background-color: #dbaaaa;"> <%
                            break;
                                case Constants.ITEM_TYPE_FOR_READ_BLOG: // Light Green
                            %> <td style="vertical-align: top; background-color: #b6e5aa;"> <%
                            break;
                            case Constants.ITEM_TYPE_FOR_SEARCH_CLICKTHRU: // Crappy yellow
                            %> <td style="vertical-align: top; background-color: #ded49a"> <%
                                break;
                                } %>
                                
                                <div>
                                    <font color="#000000">&nbsp;<%= i+1 %>. <a href="<%= bEntity.getLink() %>" title="<%= bEntity.getTitle() %>"> <%= bEntity.getTitle() %> </a></font><br>
                                    <font size="2" color="#000000">&nbsp;&nbsp;<%= bEntity.getExcerpt() %></font><br>
                                    <font size="2" color="#40528a">&nbsp;<%= bEntity.getLink() %> - <%= bEntity.getPubDate().getTime().toGMTString() %></font>
                                </div>
                                
                            </td>
                        </tr>
                        <% }
                        %>
                    </table>
                </div>
            </td>
        </tr>
    </table>
</div>